<template>
    <el-card class="box-card">
    <div slot="header" class="clearfix">
        <span>请假审批</span>
        <!-- <el-button style="float: right;margin-right:15px" type="primary" @click="dialogFormVisible = true">批量导出</el-button>
        <el-button style="float: right;margin-right:15px;margin-left:0" type="primary" @click="nextList">下一月</el-button>
        <el-button style="float: right;margin-right:15px" type="primary" @click="prevList">上一月</el-button> -->
        <el-button style="float: right;margin-right:15px" type="primary" @click="refresh">更新列表</el-button>
        
    </div>
    <!-- 用户信息列表 -->
   <div class="app-container">
    <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label='员工ID' width="95">
        <template slot-scope="scope">
          {{scope.row.userId}}
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="110" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.userName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="请假类型" width="140" align="center">
        <template slot-scope="scope">
          {{scope.row.leavetype}}
        </template>
      </el-table-column>
      <el-table-column label="请假原因" >
        <template slot-scope="scope">
          {{scope.row.leaveReason}}
        </template>
      </el-table-column>
      
      <el-table-column label="开始时间" width="180" align="center">
        <template slot-scope="scope">
          {{scope.row.leaveStartTime}}
        </template>
      </el-table-column>
      <el-table-column label="结束时间" width="180" align="center">
        <template slot-scope="scope">
          {{scope.row.leaveEndTime}}
        </template>
      </el-table-column>
      <el-table-column  label="审批" width="200" align="center">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row,index)"  v-for="(item,index) in btn" :key="index" :type="item.status" size="small">{{item.msg}}</el-button>
          <!-- <el-button @click="handleClick(scope.row)" :type="btn.danger" size="small">拒绝</el-button> -->
        </template>
      </el-table-column>
      <!-- <el-table-column class-name="status-col" label="状态" width="110" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{scope.row.status}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="截止时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span>{{scope.row.display_time}}</span>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- <div class="block" style="margin-top:20px;height:40px;">
      <el-pagination style="float:right" background layout="prev, pager, next" :total="100">
      </el-pagination>
    </div> -->
  </div>
  <!-- 添加用户popover -->
  <div class="popForm">
    <el-dialog title="填写详细信息" :visible.sync="dialogFormVisible" center>
    <el-form :model="form">
        <el-form-item label="活动名称" :label-width="formLabelWidth">
        <el-input v-model="form.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="活动区域" :label-width="formLabelWidth">
        <el-select v-model="form.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
        </el-select>
        </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">添 加</el-button>
    </div>
    </el-dialog>
    </div>
    </el-card>
    <!--添加用户弹出框 -->
    
    
</template>

<script>
import qs from "qs";
export default {
  data() {
    return {
      list: [],
      btn: [
        {
          status: "success",
          msg: "同意"
        },
        {
          status: "danger",
          msg: "拒绝"
        }
      ],
      listLoading: false,
      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      formLabelWidth: "120px"
    };
  },
  created() {
    this.$axios
        .post(
          "http://localhost:8088/getAllLeaves",
          qs.stringify({}),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          }
        )
        .then(res => {
          console.log(res.data.data);
          this.list = res.data.data
        })
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "gray",
        deleted: "danger"
      };
      return statusMap[status];
    }
  },
  methods: {
    handleClick (list,index){
        let status
        console.log(list)
        console,log(list.leaveStartTime)
        let startTime = new Date(list.leaveStartTime)
        console.log(startTime)
        if(index ==0){
          status = 1
        }else{
          status = 2
        }
        this.$axios
        .post(
          "http://localhost:8088/leaveConfirm",
          qs.stringify({
            // date: this.date
            id:list.id,
            checkState:status,
            // leaveStartTime:startTime,
            // leaveEndTime:list.leaveEndTime,
            userId:list.userId
          }),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          }
        )
        .then(res => {
          console.log(res.data);
          if(status == 1){
            this.$notify({
              title: '成功',
              message: res.data.message,
              type: 'success'
            });
          }else{
            this.$notify.error({
              title: '已拒绝',
              message: res.data.message,
              type: 'err'
            });
          }
          //刷新列表
          this.$axios
          .post(
            "http://localhost:8088/getAllLeaves",
            qs.stringify({}),
            {
              headers: {
                "Content-Type": "application/x-www-form-urlencoded"
              }
            }
          )
          .then(res => {
            console.log(res.data.data);
            this.list = res.data.data
          })
        })
      },
    refresh (){
      this.$axios
        .post(
          "http://localhost:8088/getAllLeaves",
          qs.stringify({}),
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded"
            }
          }
        )
        .then(res => {
          console.log(res.data.data);
          this.list = res.data.data
        })
    }
  }
};
</script>


<style lang="scss" scoped>
.text {
  font-size: 20px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}
.clearfix {
  span {
    font-size: 20px;
    line-height: 40px;
  }
}
.box-card {
  margin: 10px;
}

.app-container {
  padding: 0;
}
</style>




